home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
st80_vw.lha
/
st80_vw
/
speedMeasurement.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
3KB
|
64 lines
" NAME speedMeasurement.st
AUTHOR bruce@utafll.uta.edu (Bruce Samuelson)
FUNCTION measures speed using Time millisecondsToRun: block
ST-VERSIONS ParcPlace VisualWorks 1.0 and ObjectWorks 4.1
PREREQUISITES none
CONFLICTS none
DISTRIBUTION world
VERSION 1.0
DATE July 8, 1993
SUMMARY This method in the 'public domain' protocol of BlockClosure
measures the speed for running the raw code inside the block. It is
invoked by evaluating 'aBlock speed'.
Bruce Samuelson"!
'From VisualWorks(TM), Release 1.0 of 8 October 1992 on 8 July 1993 at 2:40:42 pm'!
!BlockClosure methodsFor: 'public domain'!
speed
"Copyright (c) 1993 by Bruce Samuelson. Released to the public domain.
Measure the time to evaluate the receiver minus the time to evaluate an empty
block. Return a string detailing raw execution speed of the code inside the block.
slow ['hello' , ' world'] speed
medium [1+1+1+1+1+1+1+1+1+1+1] speed
fast [1+1] speed
infinite [] speed
To get accurate measures of raw speed for fast operations such as integer
addition, the block must have many internal iterations. For example, VisualWorks
1.0 on an Amax 486/33, 256K cache, 16 MB ram, DOS 6.0, Windows 3.1 yields
1 million adds per second with [1+1] one addition inside the block
4-5 million adds per second with [1+1+...+1] 10 additions inside the block
7 million adds per second with [1+1+...+1] 100 additions inside the block.
The inability to get an accurate measurement with one internal iteration may be
partly caused by the timeBlock being copying rather than clean. Copying blocks
evaluate more slowly than the equivalent clean ones."
| minSeconds targetSeconds n emptyBlock timeBlock secondsSelf secondsEmpty t |
minSeconds := 0.1.
targetSeconds := 1.0.
n := 1.
emptyBlock := [].
timeBlock := [:bl | (Time millisecondsToRun: [n timesRepeat: bl]) * 0.001].
ObjectMemory garbageCollect.
[(t := timeBlock value: self) < minSeconds] whileTrue: [n := n * 2].
n := (n * targetSeconds / t) rounded.
ObjectMemory garbageCollect.
secondsSelf := timeBlock value: self.
ObjectMemory garbageCollect.
secondsEmpty := timeBlock value: emptyBlock.
^(t := secondsSelf - secondsEmpty) > (secondsSelf * 0.15)
ifTrue: ['
' , n printString , ' iterations
' , t printString , ' seconds (time self - time empty block)
' , (t * 1.0e6 / n) printString , ' microseconds per iteration
' , (n / t) printString , ' iterations per second']
ifFalse: ['The block is too fast to measure this way.']! !